//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow
{
    using System;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Media;
    using Microsoft.Research.ScientificWorkflow.TridentModel;
    using System.Windows;

    /// <summary>
    /// Converts the string to Brush.
    /// </summary>
    public class ColorConvert : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// Convert the string to the respective color.
        /// </summary>
        /// <param name="value">
        /// The current value.
        /// </param>
        /// <param name="targetType">
        /// The expected type.
        /// </param>
        /// <param name="parameter">
        /// Passed parameter.
        /// </param>
        /// <param name="culture">
        /// Culture.
        /// </param>
        /// <returns>
        /// Color.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return new SolidColorBrush((Color)value);
        }

        /// <summary>
        /// Returns Value.
        /// </summary>
        /// <param name="value">
        /// The current value.
        /// </param>
        /// <param name="targetType">
        /// The expected type.
        /// </param>
        /// <param name="parameter">
        /// Passed parameter.
        /// </param>
        /// <param name="culture">
        /// Culture.
        /// </param>
        /// <returns>
        /// Color.
        /// </returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }

        #endregion
    }

    /// <summary>
    /// Creates an appropriate tooltip.
    /// </summary>
    public class DataTypesLegendToolTipGenerator : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// Convert based on value and parameter.
        /// </summary>
        /// <param name="value">
        /// The current value.
        /// </param>
        /// <param name="targetType">
        /// The expected type.
        /// </param>
        /// <param name="parameter">
        /// Passed parameter.
        /// </param>
        /// <param name="culture">
        /// Culture.
        /// </param>
        /// <returns>
        /// Modified value.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            DataTypeModel typeModel = value as DataTypeModel;
            if (typeModel != null)
            {
                return DataTypesLegendToolTip(typeModel);
            }

            return value;
        }

        /// <summary>
        /// Returns Value.
        /// </summary>
        /// <param name="value">
        /// The current value.
        /// </param>
        /// <param name="targetType">
        /// The expected type.
        /// </param>
        /// <param name="parameter">
        /// Passed parameter.
        /// </param>
        /// <param name="culture">
        /// Culture.
        /// </param>
        /// <returns>
        /// Color.
        /// </returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }

        /// <summary>
        /// Creates tooltip for the Elemnt being Created.
        /// The format of the tooltip is:
        ///     Name of the Datatype
        ///     Type of the Datatype
        ///     Description of the Datatype.
        /// </summary>
        /// <returns>Returns the tooltip in the specified Format.</returns>
        private static UIElement DataTypesLegendToolTip(DataTypeModel typeModel)
        {
            StackPanel result = new StackPanel();

            TextBlock nameText = new TextBlock();
            TextBlock typeText = new TextBlock();
            TextBlock descText = new TextBlock();

            // Sets the Name of the Datatype
            nameText.Text = typeModel.Name;

            // Sets the Type of the Datatype
            typeText.Text = typeModel.Id;
            typeText.FontStyle = FontStyles.Italic;

            // Sets the Description of the Datatype
            descText.Text = typeModel.Description;

            result.Children.Add(nameText);
            result.Children.Add(typeText);
            result.Children.Add(descText);

            return result;
        }
        #endregion
    }
}
